<?php


namespace app\crontab\controller\once;


use custom\Mongo;
use think\console\Command;
use think\console\Input;
use think\console\Output;

/**
 * 入学节点同步
 * Class SchoolTimelinesSync
 * @package app\crontab\controller\once
 */
class SchoolTimelinesSync extends Command {


    protected function configure() {
        $this->setName('SchoolTimelinesSync');
    }

    protected function execute(Input $input, Output $output) {
        echo "start\n";
        $mongo = Mongo::getInstance();
        $cursor = $mongo->select('SchoolTimelines', [], ['sort' => ['id' => 1]]);
        foreach ($cursor as $k => $v) {
            if ($v->school_type == 1) {
                $school_id = db("school_primary")->where('mongo_id', $v->school_id)->value('id');
            } else {
                $school_id = db("school_middle")->where('mongo_id', $v->school_id)->value('id');
            }
            $data = [
                'school_id'     => $school_id,
                'school_type'   => $v->school_type,
                'timeline_name' => $v->timeline_name,
                'time_str'      => $v->time_str,
                'itime'         => time(),
            ];
            db("school_timelines")->insert($data);
        }
        echo "end\n";
    }

}